
using System.Web.UI.HtmlControls;
using System;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Web.UI.WebControls;
using Microsoft.VisualBasic;
using System.Collections;
using System.Web.UI;
using System.Web;


using System.IO;
using System.Text;
//using com.ddsc.database;
using DDSC.OracleADO;
using com.ddsc.common;
using SMAS;
using System.Drawing.Imaging;
using System.Resources;
using System.Data.OracleClient;

namespace smasb2b
{
	public class VNDW0032 : BasePage
	{
		
#region  Web Form 設計工具產生的程式碼
		
		//此為 Web Form 設計工具所需的呼叫。
		[System.Diagnostics.DebuggerStepThrough()]private void InitializeComponent()
		{
			
		}
		protected System.Web.UI.HtmlControls.HtmlTableCell TD1;
		// Protected WithEvents btnExit As ddscControlLibrary.SubmitButtonCtrl
		protected System.Web.UI.WebControls.Label lblVIWE;
		protected ddscControlLibrary.SubmitButtonCtrl btnExit;
		protected System.Web.UI.HtmlControls.HtmlGenericControl DIV1;
		
		//注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
		//請勿刪除或移動它。
		private System.Object designerPlaceholderDeclaration;
		
		private void Page_Init(System.Object sender, System.EventArgs e)
		{
			//CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
			//請勿使用程式碼編輯器進行修改。
			InitializeComponent();
		}
		
#endregion
		
		private void Page_Load(System.Object sender, System.EventArgs e)
		{
			//在這裡放置使用者程式碼以初始化網頁
			try
			{
				//2010/08/26 added by Ray 增加強制指定ContentType
				Response.ClearHeaders();
				Response.ClearContent();
				Response.ContentType = "image/pjpeg";
				
				string serial_no = System.Convert.ToString(this.Request["serial_no"].ToUpper());
				string code = System.Convert.ToString(this.Request["code"].ToUpper());
                dbAccess dba = new dbAccess();
                ArrayList m_arrParam = new ArrayList();
				//dbConnection dba = new dbConnection();
				//OracleConnection myConnection = dba.getOracleClientConnection();
                //string strSQL = string.Format("select serial_no,image from B2B_MATERIAL_IMAGE_SEQUENCE where code=\'{0}\' and serial_no=\'{1}\' and  status=1  ", code, serial_no);
                string strSQL = "select serial_no,image from B2B_MATERIAL_IMAGE_SEQUENCE where code=:CODE and serial_no=:serialNO and  status=1  ";
                m_arrParam.Add(dba.GetOracleParam(":CODE", code));
                m_arrParam.Add(dba.GetOracleParam(":serialNO", serial_no));
                //OracleCommand myCommand = new OracleCommand(strSQL, myConnection);
				//OracleDataAdapter MyDA = new OracleDataAdapter(myCommand);
				//DataSet ds = new DataSet();
				//MyDA.Fill(ds);
				//myConnection.Close();
				//myConnection.Dispose();
                DataSet ds = dba.runExecuteQuery("B2B_MATERIAL_IMAGE_SEQUENCE", strSQL, m_arrParam);
				byte[] byteBLOBData = null;
				//-=============================-
                byteBLOBData = (byte[])ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[0]["image"];
				//context.Response.OutputStream.Write(byteBLOBData, 0, byteBLOBData.Length)
				//Response.End()
				
				// Me.Image1.ImageUrl = byteBLOBData
				MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
				//取得圖片尺寸
				int _height = (int) (System.Drawing.Image.FromStream(stmBLOBData).PhysicalDimension.Height);
                int _width = (int)(System.Drawing.Image.FromStream(stmBLOBData).PhysicalDimension.Width);
				//準備畫布大小
                Bitmap bmp = new Bitmap(System.Drawing.Image.FromStream(stmBLOBData), new Size(_width, _height));
				//準備畫筆
				Graphics g = Graphics.FromImage(bmp);
				//畫圖從0,0開始
				g.DrawImage(bmp, 0, 0);
				stmBLOBData.Close();
				bmp.Save(Context.Response.OutputStream, ImageFormat.Jpeg);
				
				//'g.Dispose()
				Response.End();
			}
			catch (Exception ex)
			{
				showException(ex.Message);
			}
			
		}
		
	}
	
}
